#include <router/RouterRequest.h>


request RouterRequest::login(std::string_view password){
    request req;
    req.set_head({request_op::LOG_IN, gen_req_id()});
    req.set_body(const_cast<char*>(password.data()), password.size() + 1);
    return req;
}

request RouterRequest::create_forward_rule(forward_rule rule){
    request req;
    req.set_head({request_op::CREATE_FORWARD_RULE, gen_req_id()});
    rule.transform_to_network_byte_order();
    req.set_body(&rule, sizeof(rule));
    return req;
}

request RouterRequest::create_output_forward_rule(create_output_forward_rule_data data){
    request req;
    req.set_head({request_op::CRAETE_OUTPUT_FORWARD_RULE, gen_req_id()});
    data.transform_to_network_byte_order();
    req.set_body(&data, sizeof(data));
    return req;
}

request RouterRequest::create_virtual_client(create_virtual_client_data data){
    request req;
    req.set_head({request_op::CREATE_VIRTUAL_CLIENT, gen_req_id()});
    data.transform_to_network_byte_order();
    req.set_body(&data, sizeof(data));
    return req;
}

request RouterRequest::delete_virtual_client(delete_virtual_client_data data){
    request req;
    req.set_head({request_op::DELETE_FORWARD_RULE, gen_req_id()});
    data.transform_to_network_byte_order();
    req.set_body(&data, sizeof(data));
    return req;
}

uint32_t RouterRequest::gen_req_id(){
    uint32_t req_id = 0;
    return req_id++;
}
